$(document).ajaxSend(function (e,xhr,opt) {
    let token = localStorage.getItem("user_token");
    xhr.setRequestHeader("user_header_token",token)
});

$(document).ajaxError(function (event,xhr,options,exc){
    if (xhr.status == 401){
        alert("用户未登录,先登录");
        location.href = "blog_login.html";
    }
    //还可以写其他状态码触发的情况  else处理
});

function getUserInfo(url){
    $.ajax({
        type: "get",
        url:　url ,  //包括了问号
        success: function (result) {
            if (result!=null && result.code == 200 && result.data != null) {
                let userInfo = result.data;
                $(".card h3").text(userInfo.userName);
                $(".card a").attr("href", userInfo.githubUrl);
            }else {

            }
        }
    });
}

function logout() {
    let logout = confirm("是否确认退出");
    if(logout) {
        localStorage.removeItem("user_token");
        localStorage.removeItem("login_user_id");
        location.href = "blog_login.html";
    }
}




